import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/views/Home/index.vue'
import About from '@/views/About/index.vue'
import Contact from '@/views/Contact/index.vue'
import User from '@/views/User/index.vue'
import Profile from '@/views/User/Profile.vue'
import Order from '@/views/User/Order.vue'
import Wish from '@/views/User/Wish.vue'
import Coupon from '@/views/User/Coupon.vue'
import List from '@/views/List/index.vue'
import Item from '@/views/Item/index.vue'
import Bags from '@/views/Bags/index.vue'
import CheckOrder from '@/views/CheckOrder/index.vue'
import Payment from '@/views/Payment/index.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/home' // 重定向到 /home
    },
    {
      path: '/home',
      name: 'home',
      component: Home
    },
    {
      path: '/about',
      name: 'about',
      component: About
    },
    {
      path: '/contact',
      name: 'contact',
      component: Contact
    },
    {
      path: '/user',
      name: 'user',
      redirect: '/user/order',
      component: User,
      children: [
        {
          path: 'profile',
          name: 'profile',
          component: Profile
        },
        {
          path: 'order',
          name: 'order',
          component: Order
        },
        {
          path: 'wish',
          name: 'wish',
          component: Wish
        },

        {
          path: 'coupon',
          name: 'coupon',
          component: Coupon
        }
      ]
    },
    {
      path: '/list/:id',
      name: 'list',
      component: List
    },
    {
      path: '/item/:id',
      name: 'item',
      component: Item
    },
    {
      path: '/bags',
      name: 'bags',
      component: Bags
    },
    {
      path: '/checkOrder',
      name: 'checkOrder',
      component: CheckOrder
    },
    {
      path: '/payment',
      name: 'payment',
      component: Payment
    }
    // {
    //   path: '/404',
    //   name: 'notFound',
    //   component: () => import('@/views/NotFound/index.vue')
    // },
    // {
    //   path: '*',
    //   redirect: '/404'
    // }
  ]
})

router.beforeEach((to, from, next) => {
  // 路由检查
  console.log(to)
  next()
})

// 在每次路由跳转后，将滚动条设置到顶部
router.afterEach(() => {
  window.scrollTo(0, 0)
})

export default router
